package demo6;

/**
 * @Author 12629
 * @Description：
 */
class Money implements Cloneable{
    public double money=19.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person  implements Cloneable{
    public int age=10;
    public Money m = new Money();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp  = (Person) super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
        //return super.clone();
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}

public class Test {

    public static void main(String[] args) throws CloneNotSupportedException{
        Person person = new Person();
        Person person2 = (Person)person.clone();
        System.out.println(person.m.money);
        System.out.println(person2.m.money);
        System.out.println("======================");
        person2.m.money = 99.9;
        System.out.println(person.m.money);
        System.out.println(person2.m.money);
    }


    public void func() throws CloneNotSupportedException{
        //Person person = new Person();
        Person person2 = (Person) super.clone();
        //System.out.println(person);
        System.out.println(person2);
    }


    public static void main1(String[] args) throws CloneNotSupportedException {
        Test test = new Test();
        test.func();
    }
}
